package main.java.com.lee.pool;

import java.util.concurrent.*;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/12/7
 */
public class SubmitTask {

	public static void main(String[] args) throws ExecutionException, InterruptedException {
//		futureTest();
		futureExceptionTest();
	}


	private static void futureTest() throws ExecutionException, InterruptedException {
		ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
		Future<Integer> future = scheduledExecutorService.submit(() -> 123);
		System.out.println(future.get());
		scheduledExecutorService.shutdown();
	}


	private static void futureExceptionTest() {
		ExecutorService executorService = Executors.newCachedThreadPool();
		Future exceptionFuture = executorService.submit(() -> {
			throw new Exception("主动抛出异常");
		});

		try {
			exceptionFuture.get();
		} catch (InterruptedException e) {
			System.out.println("获取到线程内异常信息1");
			e.printStackTrace();
		} catch (ExecutionException e) {
			System.out.println("获取到线程内异常信息2");
			e.printStackTrace();
		}
		executorService.shutdown();

	}
}
